package com.jianglin.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jianglin.mapper.UserinfoMapper;
import com.jianglin.model.Userinfo;
import com.jianglin.service.IUserinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserinfoServiceImpl  implements IUserinfoService {
    @Autowired
    private UserinfoMapper userinfoMapper;

    @Override
    public PageInfo<Userinfo> findUserinfoAll(int page, int pageSize, Userinfo userinfo) {
        PageHelper.startPage(page, pageSize);
        List<Userinfo> list = userinfoMapper.queryUserinfoAll(userinfo);
        return new PageInfo<>(list);
    }

    // 替换原有的MyBatisPlus分页方法
    @Override
    public List<Userinfo> findListByPage(Integer page, Integer pageCount, Userinfo condition) {
        PageHelper.startPage(page, pageCount);
        return userinfoMapper.queryUserinfoAll(condition);
    }

    @Override
    public int add(Userinfo userinfo) {
        return userinfoMapper.insert(userinfo);
    }

    @Override
    public int delete(Long id) {
        return userinfoMapper.deleteById(id);
    }

    @Override
    public int updateData(Userinfo userinfo) {
        return userinfoMapper.update(userinfo);
    }

    @Override
    public Userinfo findById(Long id) {
        return userinfoMapper.selectById(id);
    }
    @Override
    public Userinfo queryUserByNameAndPwd(Userinfo userinfo) {
        return userinfoMapper.queryUserByNameAndPwd(userinfo);
    }

    @Override
    public void deleteUserByUsername(String username) {
        userinfoMapper.deleteUserByUsername(username);
    }
    @Override
    public Userinfo findUserByName(String username) {
        return userinfoMapper.findUserByName(username);
    }
}
